// Transparent coloured glass fragment shader
//
// Created by Zhiyong Yang, younthu@yahoo.com.cn, with Shader Maker.


// *****Algorithm of the coloured**********
//    Uniform filter contains the colour of glass and alpha information. alpha controls how much of color can
// pass through the glass.
//
//    For each channel of out put fragment, the result is the fragment's channel value multiply glass's alpha and 
// glass's channel value multiply (1 - glass's alpha).
// 
// Take red channel as example:
//   gl_FragColor.x=gl_FragColor.x*glass.w+glass.x*(1.0-glass.w);
//
//
// *****End of algorithm*********************
uniform float time;// 'time' contains seconds since the program was linked.
uniform sampler2D tex;
uniform vec4 glass;// colored glass

void main()
{
	gl_FragColor = gl_Color *texture2D(tex,gl_TexCoord[0].xy);

    // Code below almost the same as mix function, except that the alpha channel.
    // gl_FragColor=mix(glass, gl_FragColor, glass.w);
    gl_FragColor.x=gl_FragColor.x*glass.w+glass.x*(1.0-glass.w);
    gl_FragColor.y=gl_FragColor.y*glass.w+glass.y*(1.0-glass.w);
    gl_FragColor.z=gl_FragColor.z*glass.w+glass.z*(1.0-glass.w);

}
